package ace.cmp.spring.data.jdbc.querydsl.core.converter;

import ace.cmp.core.model.PageDto;
import ace.cmp.core.model.PageResultDto;
import java.util.List;
import java.util.function.Function;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QPageRequest;

/**
 * @author caspar
 * @date 2023/4/14 15:43
 */
public interface PageConverter {

  <T> PageResultDto<T> to(Page<T> page);

  <T, R> PageResultDto<R> to(Page<T> page, Function<T, R> mapper);

  <T, R> PageResultDto<R> toMapperList(Page<T> page, Function<List<T>, List<R>> mapper);

  PageRequest toPageRequest(PageDto page);

  QPageRequest toQPageRequest(PageDto page);

  PageDto toPageDto(Pageable pageable);

  <T, R> Page<R> toPage(PageResultDto<T> pageResultDto, Pageable pageable, Function<T, R> mapper);

  <T> Page<T> toPage(PageResultDto<T> pageResultDto, Pageable pageable);

  <T, R> Page<R> toPageMapperList(Page<T> page, Pageable pageable,
      Function<List<T>, List<R>> mapper);
}
